home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / draw_alloc.pro < prev    next >
Text File  |  1997-07-08  |  8KB  |  280 lines

  1. ;
  2. ; $Id: draw_alloc.pro,v 1.10 1997/03/18 00:07:57 lubos Exp $
  3. ;
  4. ;  WidDraw
  5. ;   Widget Draw class library
  6. ;
  7. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  8. ;   Unauthorized reproduction prohibited.
  9. ;
  10. ; MODIFICATION HISTORY
  11. ;       Written by:     Joshua Goldstein,       12/93
  12. ;
  13. ;
  14.  
  15.  
  16. ;
  17. ;  DRAW_Icon
  18. ;       Return the draw toolbar icon
  19. ;
  20. FUNCTION DRAW_Icon
  21.   RETURN, [ $
  22.     [ 255b, 255b, 255b, 255b ], $
  23.     [ 31b, 0b, 0b, 128b ], $
  24.     [ 31b, 0b, 0b, 128b ], $
  25.     [ 159b, 219b, 185b, 157b ], $
  26.     [ 153b, 255b, 249b, 159b ], $
  27.     [ 153b, 255b, 255b, 159b ], $
  28.     [ 25b, 255b, 255b, 143b ], $
  29.     [ 153b, 255b, 255b, 159b ], $
  30.     [ 153b, 255b, 255b, 159b ], $
  31.     [ 31b, 255b, 255b, 143b ], $
  32.     [ 159b, 255b, 255b, 135b ], $
  33.     [ 153b, 255b, 255b, 147b ], $
  34.     [ 153b, 127b, 255b, 153b ], $
  35.     [ 25b, 62b, 254b, 132b ], $
  36.     [ 25b, 158b, 124b, 134b ], $
  37.     [ 153b, 207b, 57b, 159b ], $
  38.     [ 159b, 231b, 147b, 159b ], $
  39.     [ 159b, 243b, 199b, 159b ], $
  40.     [ 153b, 249b, 239b, 143b ], $
  41.     [ 153b, 252b, 255b, 159b ], $
  42.     [ 25b, 254b, 255b, 159b ], $
  43.     [ 25b, 255b, 255b, 143b ], $
  44.     [ 153b, 255b, 255b, 159b ], $
  45.     [ 159b, 255b, 249b, 159b ], $
  46.     [ 159b, 219b, 185b, 157b ], $
  47.     [ 31b, 0b, 0b, 128b ], $
  48.     [ 31b, 0b, 0b, 128b ], $
  49.     [ 255b, 255b, 255b, 255b ], $
  50.     [ 255b, 255b, 255b, 255b ], $
  51.     [ 255b, 193b, 96b, 240b ], $
  52.     [ 255b, 193b, 96b, 240b ], $
  53.     [ 255b, 255b, 255b, 255b ]  $
  54.   ]
  55. END
  56.  
  57.  
  58. ;
  59. ;  DRAW_Copy
  60. ;   Copy a draw.  2 copy methods:
  61. ;
  62. ;   if( copy != NULL)       { *copy = *ptr; free(ptr); }
  63. ;   else                    { *(copy = malloc(...)) = *ptr; }
  64. ;
  65. PRO DRAW_Copy, Ptr, Copy
  66.     GenCopy, Ptr, Copy
  67. END
  68.  
  69.  
  70. ;
  71. ;  DRAW_Destroy
  72. ;   Release resources for the given draw
  73. ;
  74. PRO DRAW_Destroy, Ptr
  75.     GenDestroy, Ptr
  76. END
  77.  
  78.  
  79. ;
  80. ;  DRAW_Event
  81. ;   Event handling routine for a draw dialog.  Shares common code
  82. ;   (c.f. widbuild.pro)
  83. ;
  84. PRO DRAW_Event, Event
  85.     MISC_Event, Event, -1   ; constant is Font Offset in Foci
  86. END
  87.  
  88.  
  89. ;
  90. ;  DRAW_Build
  91. ;   Create a dialog box a draw object.  If ptr is nil then
  92. ;   create the object as well.
  93. ;
  94. PRO DRAW_Build, Ptr, ParPtr
  95.  
  96.   COMMON WidEd_Comm
  97.  
  98.     DRAW_Alloc, ParPtr, Ptr                ; Allocate object if necessary
  99.     MgrName = 'WE_DRAW' + STRTRIM(Ptr, 2)  ; Create dialog box name
  100.     IF XRegistered(MgrName) THEN RETURN     ; See if it already exists
  101.  
  102.     Title   = GetId(Ptr) + '(Child of ' + GetId(ParPtr) + ')'
  103.     Ptr2Obj, Ptr, Obj
  104.  
  105.     ;   Create dialog box
  106.  
  107.     IF SmallScreen[0] NE 0 THEN BEGIN
  108.         Base    = WIDGET_BASE(/COLUMN, TITLE=Title, GROUP_LEADER=TopDlg, $
  109.                         X_SCROLL_SIZE=SmallScreen[0], $
  110.                         Y_SCROLL_SIZE=SmallScreen[1] )
  111.     ENDIF ELSE BEGIN
  112.         Base    = WIDGET_BASE(/COLUMN, TITLE=Title, GROUP_LEADER=TopDlg)
  113.     ENDELSE
  114.     Foci    = LONARR(9)
  115.  
  116.     Base1   = WIDGET_BASE(Base, /FRAME, /COLUMN)
  117.     Lab     = WIDGET_LABEL(Base1, VALUE="Basic Information")
  118.     BuildXY, Base1, Obj, Foci, 0, /SIZE
  119.  
  120.     ;   Event Related Info
  121.  
  122.     Base2   = WIDGET_BASE(Base1,/NONEXCLUSIVE, /ROW)
  123.     Button  = WIDGET_BUTTON(Base2, VALUE='Accept Button Events', $
  124.                     UVALUE='DO_BUTTON')
  125.     IF Obj.DrawBtnEv THEN WIDGET_CONTROL, Button, /SET_BUTTON
  126.     Button  = WIDGET_BUTTON(Base2, VALUE='Accept Motion Events', $
  127.                     UVALUE='DO_MOTION')
  128.     IF Obj.DrawMoEv THEN WIDGET_CONTROL, Button, /SET_BUTTON
  129.  
  130.     Base2   = WIDGET_BASE(Base1, /FRAME, /ROW)
  131.     Lab     = WIDGET_LABEL(Base2, VALUE="Backing Store:")
  132.     Base3   = WIDGET_BASE(Base2, /ROW, /EXCLUSIVE)
  133.     Btns    = LONARR(3)
  134.     Btns[0] = WIDGET_BUTTON(Base3, VALUE='None', UVALUE='NO_STORE', /NO_REL)
  135.     Btns[1] = WIDGET_BUTTON(Base3, VALUE='Server', UVALUE='SVR_STORE', /NO_REL)
  136.     Btns[2] = WIDGET_BUTTON(Base3, VALUE='IDL', UVALUE='IDL_STORE', /NO_REL)
  137.     WIDGET_CONTROL, Btns[Obj.DrawRetain], /SET_BUTTON
  138.  
  139.     BuildOther, Base, Obj, Foci, 2, /FRAME
  140.  
  141.     Base1   = WIDGET_BASE(Base, /FRAME, /COLUMN)
  142.     Lab     = WIDGET_LABEL(Base1, VALUE="Draw Appearance Controls")
  143.     BuildXY, Base1, Obj, Foci, 5, /OFFSET, /SCROLL
  144.     BuildOkCancel, Base, Obj
  145.  
  146.     DlgInfo     = { $
  147.         Foci:       Foci, $
  148.         ObjPtr:     Ptr $
  149.     }
  150.     Obj.Dialog  = Base
  151.     WIDGET_CONTROL, Base, SET_UVALUE=DlgInfo, /NO_COPY
  152.     WIDGET_CONTROL, Base, /REALIZE
  153.     XMANAGER, MgrName, Base, EVENT_HANDLER='DRAW_Event', CLEANUP='MISC_Kill'
  154.     Obj2Ptr, Obj, Ptr
  155. END
  156.  
  157.  
  158. ;
  159. ;  DRAW_Save
  160. ;   Save draw information to a file.
  161. ;   This is a simple object to save.
  162. ;
  163. PRO DRAW_Save, Unit, Ptr
  164.     GenWrite, Unit, Ptr
  165. END
  166.  
  167.  
  168. ;
  169. ;  DRAW_Restore
  170. ;   Read in a draw object from a file
  171. ;
  172. PRO DRAW_Restore, Unit, Parent, Ptr
  173.     MISC_Restore, Unit, Parent, Ptr, "DRAW", 0
  174. END
  175.  
  176.  
  177.  
  178. ;
  179. ;  DRAW_Generate
  180. ;   Create a draw object for previewing
  181. ;
  182. PRO DRAW_Generate, Base, Ptr
  183.  
  184.   COMMON WidEd_Comm
  185.  
  186.     Ptr2Obj, Ptr, Obj
  187.     Id  = 0L            ; Prevent EXECUTE from creating a new variable
  188.  
  189.     ;   Build a command string
  190.  
  191.     Cmd = 'Id = WIDGET_DRAW(Base'
  192.     IAddCmd, Cmd, Obj.FrameSize, 'FRAME'
  193.     IAddCmd, Cmd, Obj.DrawRetain, 'RETAIN'
  194.     IAddCmd, Cmd, Obj.XSize, 'XSIZE'
  195.     IAddCmd, Cmd, Obj.YSize, 'YSIZE'
  196.     IAddCmd, Cmd, Obj.XOffset, 'XOFFSET'
  197.     IAddCmd, Cmd, Obj.YOffset, 'YOFFSET'
  198.     IAddCmd, Cmd, Obj.XScrollSize, 'X_SCROLL_SIZE'
  199.     IAddCmd, Cmd, Obj.YScrollSize, 'Y_SCROLL_SIZE'
  200.  
  201.     ; Create draw by executing the command string we just built
  202.  
  203.     IF EXECUTE(Cmd+')') NE 1 THEN BEGIN
  204.         Obj2Ptr, Obj, Ptr
  205.         MESSAGE,'Could not create Draw ' + VarName[Ptr]
  206.     ENDIF
  207.  
  208.     Obj.DrawId  = Id    ; Save widget id for TestDraw
  209.  
  210.     Obj2Ptr, Obj, Ptr
  211. END
  212.  
  213.  
  214. ;
  215. ;  DRAW_GenWid
  216. ;   Create IDL code for creating a DRAW
  217. ;
  218. PRO DRAW_GenWid, Unit, Ptr, Parent
  219.  
  220.     Name    = VarId(Ptr)            ; Get name for draw
  221.     Ptr2Obj, Ptr, Obj               ; Get object information
  222.  
  223.     XPRINTF, Unit, FORMAT='("  ",A," = WIDGET_DRAW( ",A)', $
  224.         Name, Parent, /NO_EOL
  225.     ISaveCmd, Unit, Obj.DrawBtnEv, "BUTTON_EVENTS"
  226.     ISaveCmd, Unit, Obj.FrameSize, "FRAME"
  227.     ISaveCmd, Unit, Obj.DrawMoEv, "MOTION_EVENTS"
  228.     ISaveCmd, Unit, Obj.DrawRetain, "RETAIN", /FORCE
  229.     SSaveCmd, Unit, UValue(Obj, Ptr), "UVALUE"
  230.     SSaveCmd, Unit, Obj.Value, "VALUE"
  231.     ISaveCmd, Unit, Obj.XOffset, "XOFFSET"
  232.     ISaveCmd, Unit, Obj.XSize, "XSIZE"
  233.     ISaveCmd, Unit, Obj.XScrollSize, "X_SCROLL_SIZE"
  234.     ISaveCmd, Unit, Obj.YOffset, "YOFFSET"
  235.     ISaveCmd, Unit, Obj.YSize, "YSIZE"
  236.     ISaveCmd, Unit, Obj.YScrollSize, "Y_SCROLL_SIZE"
  237.     XPRINTF, Unit, ')'
  238.  
  239.     Obj2Ptr, Obj, Ptr
  240. END
  241.  
  242.  
  243. ;
  244. ;  DRAW_Alloc
  245. ;       Allocate a draw object.  Don't allocate if ptr is non-nil
  246. ;
  247. PRO DRAW_Alloc, Parent, Ptr
  248.   COMMON WidEd_Comm    
  249.  
  250.     IF KEYWORD_SET(Ptr) NE 0 THEN RETURN    ; if(ptr != NULL) return
  251.  
  252.     Ptr = WIDGET_BASE(GROUP=TopDlg)         ; Allocate a pointer
  253.  
  254.     ;   Create a draw object
  255.  
  256.     Obj = {                     $
  257.         WE_DRAW,                $
  258.         Type:           'DRAW', $
  259.         Parent:         Parent, $ ; Pointer to parent
  260.         Id:             NewId(),$ ; Permanent Id
  261.         Dialog:         0L,     $ ; Save Dialog ID (need for Cut consistency)
  262.         Next:           0L,     $ ; index of next child/free/top
  263.         Name:           '',     $ ; Title or object name
  264.         FrameSize:      0,      $
  265.         XSize:          0,      $
  266.         YSize:          0,      $
  267.         XOffset:        0,      $
  268.         YOffset:        0,      $
  269.         XScrollSize:    0,      $
  270.         YScrollSize:    0,      $
  271.         UValue:         '',     $
  272.         Value:          '',     $
  273.         DrawId:         0L,     $
  274.         DrawBtnEv:      0,      $
  275.         DrawMoEv:       0,      $
  276.         DrawRetain:     0       $
  277.     }
  278.     Obj2Ptr, Obj, Ptr           ; Store object in pointer
  279. END
  280.